from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession

from api import dependencies
from schema.response import IPostResponseBase, IPutResponseBase
from schema.tolmut import ITolmutRead, ITolmutCreate, ITolmutPut
import crud

router = APIRouter()


@router.post('/add/', response_model=IPostResponseBase[ITolmutRead])
async def add_new_tolmut(schema: ITolmutCreate, db_session: AsyncSession = Depends(dependencies.get_db)):
    obj = await crud.tolmut.create(schema, db_session)
    obj = ITolmutRead.model_validate(obj)
    return IPostResponseBase[ITolmutRead](data=obj)


@router.put('/{tolmut_id}}/', response_model=IPutResponseBase[None])
async def modify_tolmut(tolmut_id: int, schema: ITolmutPut, db_session: AsyncSession = Depends(dependencies.get_db)):
    await crud.tolmut.modify(tolmut_id, schema, db_session)
    return IPostResponseBase[None]